import java.util.Scanner;
import java.util.SortedMap;
import java.util.TreeMap;

public class WordFrequency {

	public static void main(String[] args) {
		SortedMap<String, Integer> m = new TreeMap<String, Integer>();
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			String word = scanner.next();
			if (word.equals("exit")) {
				break;
			}
			Integer i = m.get(word);
			m.put(word, i != null ? i + 1 : 1);
		}
		System.out.println(m);
		System.out.println(m.firstKey());
		m.remove(m.firstKey());
		System.out.println(m.headMap("f"));

	}

}
